package com.zzh.leetCode.LeetCode_20211207;

import java.util.*;

/**
 * @author：zhangzhanheng
 * @createTime: 2021/12/7  10:27 上午
 * @desc:
 * @version: 1.0.0
 **/
public class Solution {
    public static int lengthOfLongestSubstring(String s) {


        HashMap<Character,Integer> map = new HashMap<>(16);
        int max = 0,start = 0;
        for (int i = 0; i < s.length(); i++) {
            char aChar = s.charAt(i);
            if (map.containsKey(aChar)) {
                start = Math.max(map.get(aChar)+1,start);
            }
            max = Math.max(max,i-start + 1);
            map.put(aChar,i);
        }
        return max;
    }

    public static void main(String[] args) {
        String a = "pwwkep";
        System.out.println(lengthOfLongestSubstring(a));
    }


}
